﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using nelech.Models.DBModel;
using System.IO;
using nelech.Models.CalendarModel;
using Google.GData.Calendar;
using Google.GData.Client;
using Google.GData.Extensions;
using System.Linq;
using System.Net;
using nelech.Controllers.Utils;
using System.Globalization;

namespace nelech.Controllers
{
    public class EventControllerUtils : Controller
    {
        CalendarService calendarService = new CalendarService("nelech");

        private void UpdateEventEntryProperties(EventEntry entry, Event e)
        {
            entry.Title.Text = e.Title;
            entry.Content.Content = e.Details;
            var startTime = new DateTime(e.Year, e.Month, e.Day, e.StartHour, e.StartMinute, 0);
            var endTime = new DateTime(e.Year, e.Month, e.Day, e.EndHour, e.EndMinute, 0);
            entry.Times.Add(new When(startTime, endTime));

            var wcl = new WebContentLink(true);
            wcl.Title = e.Title;
            if (!string.IsNullOrEmpty(e.MceDoc))
            {
                var docUrl = "http://nelech.co.il" + SharedUtils.SaveDoc(e.MceDoc, "/Upload/Texts", Server);
                wcl.WebContent.Url = docUrl;
            }
            wcl.WebContent.Width = 400;
            wcl.WebContent.Height = 400;

            HttpPostedFileBase map = Request.Files["Photo"];
            if (map != null && !string.IsNullOrEmpty(map.FileName))
            {
                var filename = SharedUtils.GetUniqueFileName(map.FileName);
                var extension = Path.GetExtension(map.FileName);
                var imagePath = SharedUtils.SaveImage(map.InputStream, "/Upload/Images", filename, extension, Server, 100L);
                var url = "http://nelech.co.il" + imagePath;
                wcl.HRef = url;
            }

            entry.WebContentLink = wcl;
        }
     

public static void HCDate()
{
            CultureInfo jewishCulture = CultureInfo.CreateSpecificCulture("he-IL");
            var hc = new System.Globalization.HebrewCalendar();
            var now = DateTime.Now;
            var day = hc.GetDayOfMonth(now);
            var month = hc.GetMonth(now);
            var year = hc.GetYear(now);

            var daysInMonth = hc.GetDaysInMonth(year, month);
            var startDay = (now - new TimeSpan(day - 1, 0, 0, 0));
            var startDate = new DateTime(startDay.Year, startDay.Month, startDay.Day, 0, 0, 0);
            var finishDate = startDate + new TimeSpan(daysInMonth - 1, 0, 0, 0);
}
       
    }
}
